package com.ultimatech.wxservice.web.controller.business;

import com.ultimatech.webappdemo.authmgr.service.IAuthService;
import com.ultimatech.webappdemo.base.BaseController;
import com.ultimatech.webappdemo.base.GroupState;
import com.ultimatech.webappdemo.base.model.SysGroup;
import com.ultimatech.wxservice.combusiness.service.IComBusinessService;
import com.ultimatech.wxservice.web.SpringUtils;

/**
 * Created by zhangleping on 2017/5/19.
 */
public class BaseBusinessController extends BaseController {

    private IAuthService authService;

    public IAuthService getAuthService() {
        return authService;
    }

    public void setAuthService(IAuthService authService) {
        this.authService = authService;
    }

    protected IComBusinessService getBusinessSvr(String name) throws Throwable {
        SysGroup group=this.getAuthService().getGroupByName(name);
        if(group!=null&&group.getState()!= GroupState.Inavailable){
            String moduleName=group.getModuleName()==null||group.getModuleName().equals("")?"comBusinessSvr":(group.getModuleName()+"Svr");
            return (IComBusinessService) SpringUtils.getBean(moduleName);
        }
        else{
            Throwable excption=new Throwable("对应商户不存在，或者商户已不可用。");
            throw excption;
        }
    }
}
